{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 数据预处理\n",
    "其实前面已经做过简单的处理，这里主要就是做数据规约。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "from sklearn.preprocessing import MinMaxScaler"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pd.read_csv(\"../tmp/data_preprocessing.csv\")\n",
    "# 从上面相关性可以看到，残余糖分和酸碱性对品质的影响不是很大，\n",
    "# 所以删除残余糖分和酸碱性两列,删除这两列后，准确率反而下降，所以这步其实是多余的。所以不需要\n",
    "# 所以可能糖分和酸碱性可能会影响口感\n",
    "df.drop([\"residual sugar\",\"pH\"],axis=1,inplace=True)\n",
    "\n",
    "# # 将数据存入tmp文件中，后续训练模型使用\n",
    "# df.to_csv(\"../tmp/model_training_data.csv\",index=False)\n",
    "\n",
    "# 又因为前面数据质量分析画的图中又许多的偏离正常值的点，且前面也分析了数据大概率是不符合正态分布的\n",
    "# 所以这里选择数据归一化处理\n",
    "# 直接使用使用 Scikit-learn 库进行数据归一化处理\n",
    "\n",
    "scaler = MinMaxScaler()\n",
    "# 用数据对 MinMaxScaler 拟合\n",
    "scaler.fit(df)\n",
    "# 对数据进行归一化处理：\n",
    "normalized_data = scaler.transform(df)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3.9.13 ('base')",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.13"
  },
  "orig_nbformat": 4,
  "vscode": {
   "interpreter": {
    "hash": "79c2bc36f36ebca92fe5f3c73355a3866f3a34a4fd0b1d43087d5313dd5fd5ff"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
